"""
# -*- coding: utf-8 -*-
# @Time    : 2023/3/3 22:19
# @Author  : 王摇摆
# @FileName: softmax.py
# @Software: PyCharm
# @Blog    ：https://blog.csdn.net/weixin_44943389?type=blog
"""
import numpy as np


def softmax(x):
    c = np.max(x)  # 取数组x中的最大值
    exp_x = np.exp(x - c)
    sum_exp_x = np.sum(exp_x)

    return exp_x / sum_exp_x


# 程序入口
x = np.array([1000, 1010, 900])
y = softmax(x)
print(y)
print(np.sum(y))
